/*
 * Copyright (C) 2015 Miquel Sas
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package traderlib.core.data.db;

/**
 * A relation between two tables.
 *
 * @author Miquel Sas
 */
public class Relation extends ForeignKey {

	/**
	 * The outer property.
	 */
	private boolean outer = false;

	/**
	 * Default constructor.
	 */
	public Relation() {
		super();
	}

	/**
	 * Check if this relation is uter.
	 *
	 * @return A boolean.
	 */
	public boolean isOuter() {
		return outer;
	}

	/**
	 * Sets the outer property.
	 *
	 * @param outer A boolean.
	 */
	public void setOuter(boolean outer) {
		this.outer = outer;
	}

	/**
	 * Gets a string representation of this relation.
	 *
	 * @return A string representation of this column spec.
	 */
	@Override
	public String toString() {
		StringBuilder b = new StringBuilder(64);
		b.append(getLocalTable().getName());
		b.append(" -> ");
		b.append(getForeignTable().getName());
		if (isOuter()) {
			b.append(" (+)");
		}
		b.append(" (");
		for (int i = 0; i < size(); i++) {
			if (i > 0) {
				b.append(", ");
			}
			b.append(get(i));
		}
		b.append(")");
		return b.toString();
	}

}
